#include <iostream>
#include <memory.h>
#include <algorithm>

using namespace std;

int r[20001];

int main(int argc, char *argv[]) {
	int v, n;
	cin >> v >> n;
	
	int box[n];
	
	for (int i=0;i<n;++i) {
		cin >> box[i];
	}
		
	memset(r, 0, sizeof(int)*20001);
	
	for (int i=0;i<n;i++) {
		for (int j=v;j>=box[i];j--) {
			r[j] = max(r[j-box[i]] + box[i], r[j]);
		}
	}
	
	cout << v - r[v] << endl;
	
	return 0;
}